import { GStatic } from "../../../Core/Manager/DataPool";

const { ccclass } = cc._decorator;
@ccclass
export class SLvData extends GStatic {
    public parse(obj: any): boolean {
        for (let i = 0; i < obj.data.length; i++) {
            let raw = GStatic.addonRaw<SLvDataRaw>(obj.data[i]);
            this._data.set(raw.lv, raw);
        }
        return true;
    }


    public getLvMinByTrait(trait: number) {
        let lv = 10000000000;
        let values = this.data.values<SLvDataRaw>();
        values.forEach(v => {
            if (v.quality === trait) {
                if (lv > v.lv) {
                    lv = v.lv;
                }
            }
        })
        return lv
    }

    /**获取最高等级 */
    public getMaxlv() {
        let values = this.data.values<SLvDataRaw>();
        let maxlLv = values[values.length - 1];
        return maxlLv
    }

    public getIdByInfo(lv) {
        let data = null;
        this.data.forEach((v: SLvDataRaw, index) => {
            if (v.lv == lv) {
                data = v;
            }
        })
        return data;
    }
}